
import io.MessageWriter;

import java.io.BufferedReader;
import java.io.File;
import java.io.FileInputStream;
import java.io.IOException;
import java.io.InputStreamReader;

import utils.DbMove;

public class Program {

	public static int getIndexOf(String[] args, String value) {
		for (int i = 0; i < args.length; i++) {
			if (args[i].equals(value)) {
				return i;
			}
		}

		return -1;
	}

	public static void main(String[] args) throws IOException {
		try{
			DbMove move = new DbMove();
			 /*String encoding="GBK";
	         File file=new File("schemaCreate.txt");
	         if(file.isFile() && file.exists()){ //判断文件是否存在
	             InputStreamReader read = new InputStreamReader(
	            new FileInputStream(file),encoding);//考虑到编码格式
	            BufferedReader bufferedReader = new BufferedReader(read);
	             String lineTxt = null;
	           while((lineTxt = bufferedReader.readLine()) != null){
	              //   System.out.println(lineTxt);
	                 move.moveTableSchema4Sql(lineTxt.toUpperCase().trim());
	             }
	             read.close();
	         }*/
			// 生成表结构
			 move.moveTableSchema4Sql("t_ipo");

		 // move.moveOneTable(true,"T_TABLE_HEADER_DEAULT_TEST");
		// move.moveOneTable(true, "TBND");
		}finally{
			MessageWriter.getInstance().close();
		}
	}

	public static void main1(String[] args) {
		try {

			if (args == null || args.length == 0) {
				System.out.println("-dbmove [-a] [-t 表名] [-d]");
				System.out.println("-seq [-a] [-s 序列名]");
			} else {
				DbMove move = new DbMove();
				if (args[0].equals("-dbmove")) {

					if (getIndexOf(args, "-a") > 0) {
						if (getIndexOf(args, "-d") > 0) {
							move.dbmove(true);
						} else {
							move.dbmove(false);
						}
					} else if (getIndexOf(args, "-t") > 0) {
						int i = getIndexOf(args, "-t");
						if (i >= args.length - 1) {
							System.out.println("-t 后面需要接表名");
						} else {
							String t = args[i + 1].toUpperCase();

							if (getIndexOf(args, "-d") > 0) {
								move.moveTableSchema(t);
								move.moveData(t);
							} else {
								move.moveTableSchema(t);
							}
						}
					}
				} else if (args[0].equals("-seq")) {
					if (getIndexOf(args, "-a") > 0) {
						move.moveSequence(null);
					} 
					else if (getIndexOf(args, "-s") > 0) {
						int i = getIndexOf(args, "-s");
						if (i >= args.length - 1) {
							System.out.println("-s 后面需要序列名");
						} else {
							String s = args[i + 1].toUpperCase();
							move.moveSequence(s);
						}

					} 

				}

			}

		} catch (

		Throwable e) {
			System.out.println(e.toString());
		} finally {
			MessageWriter.getInstance().close();
		}
	}

}
